<template>
    <div>
        <!-- 面包屑导航区 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>

        <el-card>
            <el-row>
                <el-col :span="8">
                    <el-input placeholder="请输入内容">
                        <el-button slot="append" icon="el-icon-search"></el-button>
                    </el-input>
                </el-col>
            </el-row>


        <el-table :data="orderlist" style="width: 100%" border stripe>
           <el-table-column label="#" type="index"></el-table-column>
            <el-table-column
                prop="order_number"
                label="订单编号">
            </el-table-column>

            <el-table-column
                prop="order_price"
                label="订单价格" width="100px">
            </el-table-column>

            <el-table-column label="是否付款" width="100px">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.order_pay!=='0'">已付款</el-tag>
                    <el-tag type="danger" v-else>未付款</el-tag>
                </template>
            </el-table-column>

            <el-table-column label="是否发货" prop="is_send" width="100px"></el-table-column>

            <el-table-column label="下单时间" width="200px" >
                <template slot-scope="scope">
                    {{scope.row.create_time | dataFormat}}
                </template>
            </el-table-column>

            <el-table-column label="操作" width="160px">
                <template slot-scope="scope">
                    <el-button type="primary" class="el-icon-edit" size="mini" @click="showEditAddress"></el-button>
                    <el-button type="success" class="el-icon-location" size="mini" @click="showProgress"></el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="queryInfo.pagenum"
            :page-sizes="[10, 15, 20]"
            :page-size="queryInfo.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
        ></el-pagination>
        </el-card>

        <!-- 修改地址弹框 -->
        <el-dialog
            title="修改地址"
            :visible.sync="editAddressDialogVisble"
            width="50%"
            @close="addressDialogClosed"
        >

        <!-- 修改n内容 -->
            <el-form :model="editAddress" :rules="editAddressRules" ref="editAddressRef" label-width="100px">
                <el-form-item label="省市区/县" prop="address1">
                    <el-cascader
                        v-model="editAddress.address1"
                        :options="cityDate"
                        :props="cateProps"
                        @change="handleChange">
                    </el-cascader>
                </el-form-item>

                <el-form-item label="详细地址" prop="address2">
                    <el-input v-model="editAddress.address2"></el-input>
                </el-form-item>
            </el-form>

            <span slot="footer" class="dialog-footer">
                <el-button @click="editAddressDialogVisble = false">取 消</el-button>
                <el-button type="primary" @click="editAddressDialogVisble = false">确 定</el-button>
            </span>
        </el-dialog>

        <!-- 显示物流进度 -->
        <el-dialog
            title="物流进度"
            :visible.sync="progressVisble"
            width="50%">

            <el-timeline>
                <el-timeline-item
                    v-for="(activity, index) in progessInfo"
                    :key="index"
                    :timestamp="activity.time">
                    {{activity.context}}
                </el-timeline-item>
            </el-timeline>

        </el-dialog>

    </div>
</template>

<script>
import cityDate from './citydata.js'
export default {
name:'Order',
created(){
    this.getOrderList()
},
data() {
    return {
        queryInfo:{
            query:'',
            pagenum:1,
            pagesize:10
        },
        orderlist:[],
        total:0,
        //修改地址

        editAddressDialogVisble:false,
        editAddress:{
            address1:[],
            address2:''
        },
        editAddressRules:{
            address1:[
                {required:true,message:'请输入省市区/县', trigger:'blur'}
            ],
            address2:[
                {required:true,message:'请输入详细地址', trigger:'blur'}
            ]
        },
        cityDate:cityDate,
        cateProps: {
            expandTrigger:'hover',
            value: 'value',
            label: 'label',
            children: 'children',
        },

        //显示物流
        progressVisble:false,
        progessInfo:[]
    }
},
methods:{
    async getOrderList(){
        const {data:res} = await this.$http.get('orders',{params:this.queryInfo})
        if(res.meta.status !== 200) return this.$message.error('获取订单列表失败！')
        this.orderlist = res.data.goods
        this.total = res.data.total
    },
    handleSizeChange(mewSize){
        this.queryInfo.pagesize = mewSize
        this.getOrderList()
    },
    handleCurrentChange(newPage){
        this.queryInfo.pagenum = newPage
        this.getOrderList()
    },
    showEditAddress(){
        console.log(this.cityDate);
        this.editAddressDialogVisble = true
    },
    handleChange(){

    },
    addressDialogClosed(){
        this.$refs.editAddressRef.resetFields()
    },
    async showProgress(){
        this.progressVisble = true
        const {data:res} = await this.$http.get('/kuaidi/1106975712662')
        if(res.meta.status !== 200) return this.$message.error('获取物流信息失败！')
        this.progessInfo = res.data
        console.log(res.data);

    }
}
}
</script>

<style lang='less' scoped>
@import '../../plugins/timeline/timeline.css';
@import '../../plugins/timeline-item/timeline-item.css';
.el-pagination {
    margin-top: 15px;
}
.el-cascader {
    width: 100%;
}
</style>